<template>
  <div class="app-container table-none">
    <el-form :model="queryParams" ref="queryRef" :inline="true">
      <div class="flex input-height">
        <div class="label" v-if="deptId==101">位置：</div>
        <div class="align-center" v-if="deptId==101">
          <el-tree-select v-model="queryParams.deptId" :data="deptOptions" :props="{ value: 'id', label: 'label', children: 'children' }" value-key="id"
            class="margin-right" placeholder="请选择部门" check-strictly clearable @change="bindChangeTree($event,'deptId')" />
        </div>
        <div class="label">时间：</div>
        <div class="align-center">
          <el-radio-group v-model="cycleRadio" @change="bindchangeDate" class="margin-right">
            <el-radio-button label="day">当日</el-radio-button>
            <el-radio-button label="week">本周</el-radio-button>
            <el-radio-button label="month">本月</el-radio-button>
            <el-radio-button label="season">本季</el-radio-button>
            <el-radio-button label="year">本年</el-radio-button>
          </el-radio-group>
          <el-date-picker style="margin-right:8px" v-model="dateSection" type="daterange" range-separator="至" start-placeholder="开始时间" end-placeholder="结束时间"
            @change="bindChangeAllDate" />
        </div>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </div>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="Plus" @click="handleAdd()" v-hasPermi="['audit:over:add']">上报</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="Download" @click="handleExport" v-hasPermi="['audit:stat:export']">导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="Menu" @click="handleStatistics">统计</el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
    </el-row>
    <!-- height="800" -->
    <el-table :data="tableData" style="width: 100%;" :header-cell-style="{ 'text-align': 'center '}" :cell-style="cellStyle" :span-method="objectSpanMethod"
      show-overflow-tooltip>
      <template v-for="(item,index) in config.goOutContent">
        <el-table-column :label="item.title" v-if="item.children" align="center">
          <template v-for="(element) in item.children">
            <el-table-column :prop="element.prop" :label="element.title" align="center" v-if="!element.children" />
            <el-table-column :label="element.title" v-else align="center">
              <template v-for="(option) in element.children">
                <el-table-column :prop="option.prop" align="center" :label="option.title" />
              </template>
            </el-table-column>
          </template>
        </el-table-column>
        <el-table-column :prop="item.prop" :label="item.title" align="center" :width="item.width" :fixed="item.fixed" v-else>
          <template #default="scope">
            <span v-if="item.render&&item.prop!='auditPicture'&&item.prop!='dzptPicture'">
              {{item.render(scope.row[item.prop],scope.row)}}</span>
            <el-button @click="bindShowImg(scope.row[item.prop])" v-else-if="item.prop=='auditPicture'||item.prop=='dzptPicture'">查看</el-button>
            <span v-else>{{ scope.row[item.prop]=='null'?'-':scope.row[item.prop] }}</span>
          </template>
        </el-table-column>
      </template>
      <el-table-column prop="index" label="操作" width="220" fixed="right">
        <template #default="scope">
          <el-button link icon="Edit" size="small" v-hasPermi="['audit:stat:edit']" type="primary" @click.prevent="editRowList(scope.row)">
            修改
          </el-button>
          <el-button link icon="Edit" size="small" v-if="deptId==101" type="primary" @click.prevent="editRow(scope.row,1)">
            查看详情
          </el-button>
          <el-popconfirm title="确认删除本条数据?" v-if="deptId!=101" v-hasPermi="['audit:over:remove']" @confirm="deleteRow(scope.row)">
            <template #reference>
              <el-button link icon="Delete" type="primary" size="small">
                删除
              </el-button>
            </template>
          </el-popconfirm>

        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
    <!-- 添加或修改流程分类对话框 -->
    <el-dialog :title="dialogType==1?'总量录入':'稽核工单处理上报'" v-model="dialogTotal" width="1200px" append-to-body :close-on-click-modal="false">
      <el-form :model="queryDialogParams" ref="queryRef" :inline="true">
        <el-form-item label="收费站" prop="deptId">
          <el-tree-select v-model="rowDetails.deptId" :data="deptOptions" :props="{ value: 'id', label: 'label', children: 'children' }" value-key="id"
            placeholder="请选择收费站" check-strictly clearable :disabled="true" />
        </el-form-item>
        <!-- 正式版需要禁止:disabled="true"，试用期为:disabled="false" -->
        <el-form-item label="日期" prop="date">
          <el-date-picker v-model="rowDetails.date" type="date"  @change="bindChangeDate" />
        </el-form-item>
        <el-form-item label="经办人" prop="userName">
          <el-input v-model="rowDetails.userName" placeholder="请输入经办人" clearable :disabled="true" />
        </el-form-item>
      </el-form>
      <div>
        <div class="title"><span class="text-large font-600 mr-3"> 稽核分析系统 </span></div>
        <el-table :data="dialogTableData" style="width: 100%" :span-method="arraySpanMethod" show-overflow-tooltip>
          <el-table-column prop="type" label="类型" align="center" />
          <el-table-column prop="name" label="稽核项" align="center" />
          <el-table-column prop="num" label="总量" align="center">
            <template #default="scope">
              <el-input-number :controls="false" v-model="rowDetails[scope.row.prop]" placeholder="请输入" :disabled="dialogType==2"
                @input="bindChangeRoutine($event,scope.row.prop,scope.$index)" class="inputDeep" input-style="textAlign:center" />
            </template>
          </el-table-column>
          <el-table-column prop="num2" label="处理量" align="center" v-if="dialogType==2">
            <template #default="scope">
              <el-input-number :controls="false" v-model="rowDetails[scope.row.propHand]" placeholder="请输入"
                @input="bindChangeRoutine($event,scope.row.propHand,scope.$index)" class="inputDeep" input-style="textAlign:center" />
            </template>
          </el-table-column>
        </el-table>

        <!-- <div v-if="dialogType==2">

          <div class="title"><span class="text-large font-600 mr-3"> 印证资料 </span></div>
          <ImageUpload :modelValue="auditPicture" v-model="auditPicture" />
        </div> -->

        <div class="title"><span class="text-large font-600 mr-3"> 对账平台 </span></div>
        <el-descriptions border :style="{width: dialogType==2?'800px':'400px'}">
          <el-descriptions-item label="总量">
            <el-input-number :controls="false" v-model="rowDetails.dzptTotal" :disabled="dialogType==2" placeholder="请输入"
              @input="bindChangeRoutine($event,'dzptTotal')" class="inputDeep" input-style="textAlign:center" />
          </el-descriptions-item>
          <el-descriptions-item label="处理量" v-if="dialogType==2">
            <el-input-number :controls="false" v-model="rowDetails.dzptCount" placeholder="请输入" @input="bindChangeRoutine($event,'dzptCount')" class="inputDeep"
              input-style="textAlign:center" />
          </el-descriptions-item>
        </el-descriptions>
        <!-- <div class="margin-top" v-if="dialogType==2">
          <ImageUpload :modelValue="dzptPicture" v-model="dzptPicture" />
        </div> -->

        <div class="margin-top" v-if="dialogType==2">
          <el-descriptions border style="width: 1050px;">
            <el-descriptions-item label="加入省内黑名单">
              <el-input-number :controls="false" v-model="rowDetails.jrsnhmdCount" placeholder="请输入" @input="bindChangeRoutine($event,'jrsnhmdCount')"
                class="inputDeep" input-style="textAlign:center" />
            </el-descriptions-item>
            <el-descriptions-item label="转部级追缴">
              <el-input-number :controls="false" v-model="rowDetails.zbjzjCount" placeholder="请输入" @input="bindChangeRoutine($event,'zbjzjCount')"
                class="inputDeep" input-style="textAlign:center" />
            </el-descriptions-item>
            <el-descriptions-item label="追缴金额">
              <el-input-number :controls="false" v-model="rowDetails.zjAmount" placeholder="请输入" @input="bindChangeRoutine($event,'zjAmount')"
                class="inputDeep" input-style="textAlign:center"><template #suffix>
                  <span>元</span>
                </template></el-input-number>
            </el-descriptions-item>
          </el-descriptions>
        </div>
      </div>

      <template #footer>
        <div class="dialog-footer" v-if="!isView">
          <el-button type="primary" @click="submitForm"> {{dialogType==2?"保存":'保存并开始上报'}}</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>

    <el-dialog v-model="dialogVisibleImg">
      <ImagePreview :src="dialogImageUrl" />
    </el-dialog>
    <Statistics :tableData="statisticsData" ref="statisticsRef" @changeType="handleStatistics" />
  </div>
</template>

<script setup>
import moment from 'moment'
import { deptTreeSelect } from "@/api/system/user";
import { listStat, getAudit_zl, getAudit_cl, listAudit_zl, updateAudit_zl, updateAudit_cl, delStat, addAudit_zl, addAudit_cl, getStat, auditEdit,postMonthList, } from "@/api/charge/audit";
import useUserStore from '@/store/modules/user'
import config from "./config"
import ImagePreview from "@/components/ImagePreview"
import Statistics from "./components/Statistics.vue";

const { proxy } = getCurrentInstance()
const rowNameList = ref(['rkdzTotal', 'czjcTotal', 'cktqTotal', 'cxbfTotal', 'yrwcTotal'])
const queryParams = ref({ pageNum: 1, pageSize: 30 })
const tableData = ref([])
const userStore = useUserStore()
const dialogTotal = ref(false)
const queryDialogParams = ref({})
const dialogPostData = ref()
const cycleRadio = ref('day')
const deptOptions = ref([])
const dialogType = ref(1)
const dialogTableData = ref([{ type: '内部稽核', name: "入口丢轴稽核", prop: 'rkdzTotal', propHand: "rkdzCount" }, { type: '内部稽核', name: "称重检测数据稽核", prop: 'czjcTotal', propHand: "czjcCount" }, { type: '特情复核', name: "出口特情稽核", prop: 'cktqTotal', propHand: "cktqCount" }, { type: '逃费稽核', name: "车型不符稽核", prop: 'cxbfTotal', propHand: "cxbfCount" }, { type: '逃费稽核', name: "有入无出稽核", prop: 'yrwcTotal', propHand: "yrwcCount" }])
const rowDetails = ref({})
const dateSection = ref([])
const userId = ref();
const deptId = ref()
const userName = ref()
const dzptPicture = ref('')
const auditPicture = ref('')
const dialogImageUrl = ref("")
const dialogVisibleImg = ref(false)
const dealId = ref()
const isView = ref(false)
const isEdit = ref(false)
const total = ref(0)
const statisticsData = ref([])
const statisticsRef = ref()


// 表格
const arraySpanMethod = ({
  row,
  column,
  rowIndex,
  columnIndex,
}) => {
  if (columnIndex === 0) {
    const currentValue = row["type"];
    // 获取上一行相同列的值
    const preRow = dialogTableData.value[rowIndex - 1];
    const preValue = preRow ? preRow["type"] : null;
    if (currentValue === preValue) {
      return { rowspan: 0, colspan: 0 };
    } else {
      // 否则计算当前单元格应该跨越多少行
      let rowspan = 1;
      for (let i = rowIndex + 1; i < dialogTableData.value.length; i++) {
        const nextRow = dialogTableData.value[i];
        const nextValue = nextRow["type"];
        if (nextValue === currentValue) {
          rowspan++;
        } else {
          break;
        }
      }
      return { rowspan, colspan: 1 };
    }
  }

}

const objectSpanMethod = ({ row, column, rowIndex, columnIndex }) => {
  let arr = [1, 3, 5, 6, 8, 9, 11, 12, 14, 15, 17, 20, 22, 23, 24, 25]
  let arr2 = [2, 4, 6, 7, 9, 10, 12, 13, 15, 16, 18, 21, 23, 24, 25, 26]

  let flag = deptId.value == 101 ? arr2.includes(columnIndex) : arr.includes(columnIndex)
  if (flag) {
    const currentValue = row["deptName"];
    const currentValue2 = row["date"];
    // 获取上一行相同列的值
    const preRow = tableData.value[rowIndex - 1];
    const preValue = preRow ? preRow["deptName"] : null;
    const preValue2 = preRow ? preRow["date"] : null;
    if (currentValue === preValue && preValue2 === currentValue2) {
      return { rowspan: 0, colspan: 0 };
    } else {
      // 否则计算当前单元格应该跨越多少行
      let rowspan = 1;
      for (let i = rowIndex + 1; i < tableData.value.length; i++) {
        const nextRow = tableData.value[i];
        const nextValue = nextRow["deptName"];
        const nextValue2 = nextRow["date"];
        if (nextValue === currentValue && nextValue2 == currentValue2) {
          rowspan++;
        } else {
          break;
        }
      }
      return { rowspan, colspan: 1 };
    }
  } else if (columnIndex === 0) {
    const currentValue = row["date"];
    // 获取上一行相同列的值
    const preRow = tableData.value[rowIndex - 1];
    const preValue = preRow ? preRow["date"] : null;
    if (currentValue === preValue) {
      return { rowspan: 0, colspan: 0 };
    } else {
      // 否则计算当前单元格应该跨越多少行
      let rowspan = 1;
      for (let i = rowIndex + 1; i < tableData.value.length; i++) {
        const nextRow = tableData.value[i];
        const nextValue = nextRow["date"];
        if (nextValue === currentValue) {
          rowspan++;
        } else {
          break;
        }
      }
      return { rowspan, colspan: 1 };
    }
  }



};
// 样式
const cellStyle = ({ row, column, rowIndex, columnIndex }) => {
  if (deptId.value == 101) {
    if (columnIndex == 4 || columnIndex == 5 || columnIndex == 6 || columnIndex == 7 || columnIndex == 8 || columnIndex == 9) {
      return { background: "#e9e9eb" };
    } else if (columnIndex == 10 || columnIndex == 11 || columnIndex == 12) {
      return { background: "#FAFAFA" };
    } else if (columnIndex == 13 || columnIndex == 14 || columnIndex == 15 || columnIndex == 16 || columnIndex == 17 || columnIndex == 18) {
      return { background: "#e9e9eb" };
    } else if (columnIndex == 21 || columnIndex == 22 || columnIndex == 23) {
      return { background: "#E6E8EB" };
    } else if (columnIndex == 26) {
      return { background: "#DEFFE0" };
    }
  } else {
    if (columnIndex == 3 || columnIndex == 4 || columnIndex == 5 || columnIndex == 6 || columnIndex == 7 || columnIndex == 8) {
      return { background: "#e9e9eb" };
    } else if (columnIndex == 9 || columnIndex == 10 || columnIndex == 11) {
      return { background: "#FAFAFA" };
    } else if (columnIndex == 12 || columnIndex == 13 || columnIndex == 14 || columnIndex == 15 || columnIndex == 16 || columnIndex == 17) {
      return { background: "#e9e9eb" };
    } else if (columnIndex == 20 || columnIndex == 21 || columnIndex == 22) {
      return { background: "#E6E8EB" };
    } else if (columnIndex == 25) {
      return { background: "#DEFFE0" };
    }
  }

}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  let strDate = moment().format("YYYY-MM-DD")
  queryParams.value = { pageNum: 1, pageSize:30, startDate: strDate, endDate: strDate, deptId: deptId.value }
  cycleRadio.value = 'day'
  getList()
}
function getDeptTree() {
  deptTreeSelect().then(response => {
    deptOptions.value = response.data;
  });
};
const bindChangeRoutine = (val, name) => {
  rowDetails.value[name] = val;
}
const cancel = () => {
  if (dialogType.value == 2) {
    proxy.$confirm("确认取消提交？", "提示", {
      confirmButtonText: "确 认",
      cancelButtonText: "取 消"
    }).then(() => {
      dialogTotal.value = false;
      dialogType.value = 1;
    }).catch(() => {

    });
  } else {
    dialogTotal.value = false;
  }



}
const handleAdd = (time) => {
  // 先查询今日是否已经填写
  isView.value = false;
  let startDate = time ? time : moment().format("YYYY-MM-DD")
  listStat({ ...queryParams.value, ...{ startDate, endDate: startDate, deptId: deptId.value } }).then(res => {
    if (res.code == 200 && res.rows && res.rows.length) {
      let arr = res.rows.filter(item => item.userId == userId.value)
      if (arr && arr.length) {
        editRow(arr[0])
      } else {
        dialogType.value = 2;
        dialogTotal.value = true;
        dialogTableData.value = [{ type: '内部稽核', name: "入口丢轴稽核", prop: 'rkdzTotal', propHand: "rkdzCount" }, { type: '内部稽核', name: "称重检测数据稽核", prop: 'czjcTotal', propHand: "czjcCount" }, { type: '特情复核', name: "出口特情稽核", prop: 'cktqTotal', propHand: "cktqCount" }, { type: '逃费稽核', name: "车型不符稽核", prop: 'cxbfTotal', propHand: "cxbfCount" }, { type: '逃费稽核', name: "有入无出稽核", prop: 'yrwcTotal', propHand: "yrwcCount" }]
        auditPicture.value = ""
        dzptPicture.value = ""
        getAudit_zl(res.rows[0].taskId).then(res => {
          if (res.code == 200) {
            rowDetails.value = res.data;
          }
        })
      }
    } else {

      dialogTableData.value = [{ type: '内部稽核', name: "入口丢轴稽核", prop: 'rkdzTotal', propHand: "rkdzCount" }, { type: '内部稽核', name: "称重检测数据稽核", prop: 'czjcTotal', propHand: "czjcCount" }, { type: '特情复核', name: "出口特情稽核", prop: 'cktqTotal', propHand: "cktqCount" }, { type: '逃费稽核', name: "车型不符稽核", prop: 'cxbfTotal', propHand: "cxbfCount" }, { type: '逃费稽核', name: "有入无出稽核", prop: 'yrwcTotal', propHand: "yrwcCount" }]

      dialogTotal.value = true;
      dialogType.value = 1;
      rowDetails.value = {
        date: time ? time : moment().format("YYYY-MM-DD"),
        deptId: deptId.value,
        userId: userId.value,
        userName: userName.value
      }
    }
  }).catch(err => {
    dialogTotal.value = true;
    dialogType.value = 1;
    rowDetails.value = {
      date: moment().format("YYYY-MM-DD"),
      deptId: deptId.value,
      userId: userId.value,
      userName: userName.value
    }
  })


}
const editRowList = (data) => {
  let indexArr = []
  let oldArr = [{ type: '内部稽核', name: "入口丢轴稽核", prop: 'rkdzTotal', propHand: "rkdzCount" }, { type: '内部稽核', name: "称重检测数据稽核", prop: 'czjcTotal', propHand: "czjcCount" }, { type: '特情复核', name: "出口特情稽核", prop: 'cktqTotal', propHand: "cktqCount" }, { type: '逃费稽核', name: "车型不符稽核", prop: 'cxbfTotal', propHand: "cxbfCount" }, { type: '逃费稽核', name: "有入无出稽核", prop: 'yrwcTotal', propHand: "yrwcCount" }]
  isEdit.value = true;
  dealId.value = data.dealId;
  getAudit_zl(data.taskId).then(res => {
    if (res.code == 200) {
      rowDetails.value = { ...{ userName: data.userName }, ...res.data };
      if (!data.dealId) return;
      getAudit_cl(data.dealId).then(reson => {
        if (reson.code == 200) {
          rowDetails.value = { ...reson.data, ...rowDetails.value, };
          auditPicture.value = reson.data.auditPicture;
          dzptPicture.value = reson.data.dzptPicture;

          rowNameList.value.forEach((item, index) => {
            // if (rowDetails.value[item] != 0) {

            // }
            indexArr.push(index);
          })
          let arr = oldArr.filter((item, index) => indexArr.includes(index));
          dialogTableData.value = arr;
          dialogTotal.value = true;
          dialogType.value = 1;

        }
      })
    }
  })

}

const editRow = (data, type) => {
  let indexArr = []
  let oldArr = [{ type: '内部稽核', name: "入口丢轴稽核", prop: 'rkdzTotal', propHand: "rkdzCount" }, { type: '内部稽核', name: "称重检测数据稽核", prop: 'czjcTotal', propHand: "czjcCount" }, { type: '特情复核', name: "出口特情稽核", prop: 'cktqTotal', propHand: "cktqCount" }, { type: '逃费稽核', name: "车型不符稽核", prop: 'cxbfTotal', propHand: "cxbfCount" }, { type: '逃费稽核', name: "有入无出稽核", prop: 'yrwcTotal', propHand: "yrwcCount" }]
  if (type == 1) {
    isView.value = true
  } else {
    isView.value = false
  }
  dealId.value = data.dealId;
  isEdit.value = false;
  getAudit_zl(data.taskId).then(res => {
    if (res.code == 200) {
      rowDetails.value = { ...{ userName: data.userName }, ...res.data };
      if (!data.dealId) return;
      getAudit_cl(data.dealId).then(reson => {
        if (reson.code == 200) {
          rowDetails.value = { ...reson.data, ...rowDetails.value, };
          auditPicture.value = reson.data.auditPicture;
          dzptPicture.value = reson.data.dzptPicture;


          rowNameList.value.forEach((item, index) => {
            if (rowDetails.value[item] != 0) {
              indexArr.push(index);
            }
          })
          let arr = oldArr.filter((item, index) => indexArr.includes(index));
          dialogTableData.value = arr;
          dialogTotal.value = true;
          dialogType.value = 2;

        }
      })
    }
  })

}

const submitForm = () => {
  let indexArr = []
  if (dialogType.value == 1) {
    rowNameList.value.forEach((item, index) => {
      if (rowDetails.value[item] != 0) {
        indexArr.push(index)
      }
    })
    let arr = dialogTableData.value.filter((item, index) => indexArr.includes(index))
    dialogTableData.value = arr
  }

  if (dialogType.value == 1 && !rowDetails.value.taskId) {
    // 新增修改 dzptTotal
   
    if (rowDetails.value.rkdzTotal == null || rowDetails.value.czjcTotal == null || rowDetails.value.cktqTotal == null || rowDetails.value.cxbfTotal == null || rowDetails.value.yrwcTotal == null) {
      proxy.$modal.msgError("您有总量未填写");
      return
    }
    dialogType.value = 2;
  } else if (dialogType.value == 2 && !rowDetails.value.dealId) {
    if (rowDetails.value.rkdzCount > rowDetails.value.rkdzTotal || rowDetails.value.czjcCount > rowDetails.value.czjcTotal || rowDetails.value.cktqCount > rowDetails.value.cktqTotal || rowDetails.value.cxbfCount > rowDetails.value.cxbfTotal || rowDetails.value.yrwcCount > rowDetails.value.yrwcTotal) {
      proxy.$modal.msgError("您有处理量大于总量");
      return
    }
    addAudit_zl({ ...rowDetails.value, userId: userId.value, userName: userName.value }).then(reson => {
      if (reson.code == 200) {
        addAudit_cl({ ...rowDetails.value, auditPicture: auditPicture.value, dzptPicture: dzptPicture.value, taskId: reson.data.taskId, userId: userId.value, userName: userName.value }).then(res => {
          if (res.code == 200) {
            proxy.$modal.msgSuccess("提交成功");
            dialogTotal.value = false;
            dialogType.value = 1;
            dzptPicture.value = "";
            auditPicture.value = "";

            getList()
          }
        })
      }
    })

  } else if (dialogType.value == 1) {
    // 总量修改，弃用 
    // updateAudit_zl(rowDetails.value).then(res => {
    //   if (res.code == 200) {
    //     getAudit_cl(dealId.value).then(reson => {
    //       if (reson.code == 200) {
    //         auditPicture.value = reson.data.auditPicture
    //         dzptPicture.value = reson.data.dzptPicture
    //         rowDetails.value = { ...reson.data, ...rowDetails.value };
    //         proxy.$modal.msgSuccess("提交成功");
    //         dialogType.value = 2;
    //       }
    //     })

    //   }
    // })
    // 试用期使用
    auditEdit(rowDetails.value).then(res => {
      dialogType.value = 2;
      auditPicture.value = res.data.auditPicture
      dzptPicture.value = res.data.dzptPicture
      rowDetails.value = { ...res.data, ...rowDetails.value };
      proxy.$modal.msgSuccess("提交成功");

    })

  } else {
    if (rowDetails.value.rkdzCount > rowDetails.value.rkdzTotal || rowDetails.value.czjcCount > rowDetails.value.czjcTotal || rowDetails.value.cktqCount > rowDetails.value.cktqTotal || rowDetails.value.cxbfCount > rowDetails.value.cxbfTotal || rowDetails.value.yrwcCount > rowDetails.value.yrwcTotal) {
      proxy.$modal.msgError("您有处理量大于总量");
      return
    }
    updateAudit_cl({ ...rowDetails.value, auditPicture: auditPicture.value, dzptPicture: dzptPicture.value, userId: userId.value, userName: userName.value }).then(res => {
      if (res.code == 200) {
        updateAudit_zl(rowDetails.value).then(reson => {
          if (reson.code == 200) {
            proxy.$modal.msgSuccess("提交成功");
            dialogTotal.value = false;
            dialogType.value = 1;
            dzptPicture.value = "";
            auditPicture.value = "";
            getList()
          }

        })

      }
    })
  }
}

const bindChangeDate = (val) => {
  rowDetails.value.date = moment(val).format("YYYY-MM-DD")
  handleAdd(rowDetails.value.date)
}
const bindChangeTree = (val, name) => {
  queryParams.value[name] = val;
  getList();
}
const bindChangeAllDate = (val) => {
  if (!val) { dateSection.value = []; return }
  dateSection.value = [moment(val[0]).format("YYYY-MM-DD"), moment(val[1]).format("YYYY-MM-DD")]
}
const handleQuery = () => {
  queryParams.value.startDate = dateSection.value[0];
  queryParams.value.endDate = dateSection.value[1];
  getList();
}
const deleteRow = (data) => {
  if (data.taskId) {
    delStat({ id: data.dealId }).then(res => {
      if (res.code == 200) {
        proxy.$modal.msgSuccess("删除成功");
        getList()
      }
    })
  }
}

const getList = () => {
  listStat(queryParams.value).then(res => {
    if (res.code == 200) {
      tableData.value = res.rows;
      total.value = res.total;
    }
  })
}
/** 导出按钮操作 */
function handleExport() {
  proxy.download('audit/stat/export', {
    ...queryParams.value
  }, `稽核工单完成情况_${new Date().getTime()}.xlsx`)
}
const bindchangeDate = (val) => {
  let date = new Date();
  let year = date.getFullYear();
  let params = {}
  if (val == 'day') {
    params.startDate = moment().format("YYYY-MM-DD")
    params.endDate = moment().format("YYYY-MM-DD");
  } else if (val == 'week') {
    params.startDate = moment().startOf('week').format('YYYY-MM-DD');
    params.endDate = moment().endOf('week').format('YYYY-MM-DD')
  } else if (val == 'month') {
    params.startDate = moment().startOf('month').format('YYYY-MM-DD');
    params.endDate = moment().endOf('month').format('YYYY-MM-DD')
  } else if (val == 'season') {
    let startQuarter = moment(moment().quarter(moment().quarter()).startOf('quarter').valueOf()).format('YYYY-MM-DD');
    let endQuarter = moment(moment().quarter(moment().quarter()).endOf('quarter').valueOf()).format('YYYY-MM-DD');
    params.startDate = startQuarter
    params.endDate = endQuarter
  } else {
    params.startDate = year + '-01-01'
    params.endDate = year + '-12-31'
  }
  dateSection.value = [moment(params.startDate).format("YYYY-MM-DD"), moment(params.endDate).format("YYYY-MM-DD")]
  queryParams.value = { ...queryParams.value, ...params }; getList()


}
const bindShowImg = (src) => {
  dialogVisibleImg.value = true;
  dialogImageUrl.value = src
}
const getDeptId = () => {
  userStore.getInfo().then(res => {
    if (res.code == 200) {
      deptId.value = res.user.dept.deptId;
      userId.value = res.user.userId;
      userName.value = res.user.userName;
      queryParams.value.deptId = deptId.value
      if (deptId.value != 101 && config.goOutContent.length >= 14) {
        config.goOutContent.splice(1, 1)
      }
      getList()
    }

  })
}
const start = () => {
  let strDate = moment().format("YYYY-MM-DD")
  dateSection.value = [strDate, strDate];
  queryParams.value.startDate = strDate;
  queryParams.value.endDate = strDate;
}


function handleStatistics(date) {
  // 本年  本季度  本月
  if (!date || !date.startDate) {
    date.startDate = moment().format('YYYY-MM') + '-01'
    date.endDate = moment().endOf('month').format('YYYY-MM-DD')
  }
  statisticsData.value= []
  postMonthList({
    "startTime": date.startDate,
    "endTime": date.endDate,
    deptId:deptId.value
    // "type": type.value
  }).then(res => {
    if (res.code == 200 && res.rows) {
      statisticsData.value=res.rows
    
      statisticsRef.value.open();
    }
  })
}


getDeptId()
getDeptTree()
start()

</script>

<style scoped>
.flex {
  display: flex;
  align-items: center;
  margin-bottom: 12px;
}

.flex .label {
  color: #333;
  font-size: 14px;
}
.margin-right-lg {
  margin-right: 32px;
}
.margin-right {
  margin-right: 8px;
}
.align-center {
  display: flex;
  align-items: center;
}
.margin-top {
  margin-top: 20px;
}
/deep/ .input-height .el-input__wrapper {
  height: 32px;
}
/deep/ .input-height .el-date-editor.el-input {
  height: 32px;
}
.title {
  position: relative;
  font-size: 18px;
  font-weight: 800;
  margin: 20px 0;
}
.title::before {
  content: "";
  display: block;
  position: absolute;
  width: 100px;
  height: 6px;
  bottom: 0;
  background: linear-gradient(270deg, rgba(248, 115, 115, 0) 0%, #2252d6 100%);
  border-radius: 3px;
  opacity: 0.7;
}
.inputDeep >>> .el-input__wrapper {
  width: 100%;
  height: 30px;
  line-height: 30px;
  box-shadow: none !important;
  /* border-bottom: 1px solid #eee; */
}
</style>